// index.js
const computedBehavior = require('miniprogram-computed').behavior
Page({
  behaviors: [computedBehavior],
  computed:{
    totalPrice(data){
      return data.product.price * data.product.num
    }
  },
  data: {
    wuhu: '芜湖起飞~',
    product: {
      name: "锐刻五代",
      price: 398,
      num: 1
    },
    students: [
      { id: 1, name: '小明', age: 18, gender: '男' },
      { id: 2, name: '小红', age: 17, gender: '女' },
      { id: 3, name: '小刚', age: 19, gender: '男' },
      { id: 4, name: '小丽', age: 18, gender: '女' },
      { id: 5, name: '小米', age: 19, gender: '女' },
    ],
    fruit: ['🍌', '🍎', '🍑', '🍓'],
    isShow: true,
    isShowText:'隐藏'
  },
  navigateTo() {
    wx.navigateTo({
      url: '/pages/index3/index3',
    });
  },
  add() {
    this.setData({
      'product.num': this.data.product.num + 1
    })
  },
  del() {
    // 方法一 变化数据较少时使用
    // this.setData({
    //   'product.num':this.data.product.num - 1
    // })

    // 方法二 变化数据较多时使用
    if (this.data.product.num <= 1) return
    this.setData({
      product: {
        ...this.data.product,
        num: this.data.product.num - 1,
      }
    })
  },
  show() {
    this.setData({
      'isShow':!this.data.isShow,
      'isShowText':this.data.isShowText==='显示'?'隐藏':'显示'
    })
  }

})
